<template>
      <div>

          <div style="margin: 10px 0">
              <div style="margin: 10px 0">客户群管理：</div>
              <!-- 列表 -->
              <UpdateClientsTags :clientNum="multipleSelection.length"/>
              <span slot="footer" class="dialog-footer">
                  <el-button type="primary" @click="updateClientTags()">确定</el-button>
                  <el-button @click="back">返回</el-button>
              </span>
          </div>
      </div>
</template>

<script>
    import UpdateClientsTags from "@/views/custGroup/manage/client_update_tags"
    export default {
        components: {
            UpdateClientsTags
        },
        name: "group_event",
        props: {
            rowId: {
                type: Array,
                default: ''
            }
        },
        data() {
            return {
                groupTagsData:[{
                    tagGroupName:'客户阶段',
                    tagName:'新客户，回购客户'
                },{
                    tagGroupName:'客户',
                    tagName: '一般客户，重要客户'
                }],
                tagsData:[{
                    clientTagsName:'客户阶段'
                },{
                    clientTagsName:'客户'
                }],
                input:'',
                multipleSelection: [],
            }
        },

        methods: {
            back() {
                this.$emit("currentHandler","list")
            },
            selectTag(){
                let that = this
                this.$request("/api/tags/getGroupTagsByParams/1_0?data=null", "", "POST").then((data) => {
                    that.tagsData=date.tagsData
                })

            },
            addTag(){

            },
            showInput(){

            },
            addTagGroup(){

            },
            updateClientTags(){
                let newTag = this.$refs.setClientsTags.getData()
                let newUnionTag = []

                newTag.map((item) => {
                    newUnionTag.push(item.tagId)
                })

                alert(this.rowId.length)

                this.multipleSelection.map((item) => {
                    if (item.unionTag == null) {
                        item['unionTag'] = newTag
                    } else {
                        let newUnionTag = JSON.parse(item['unionTag']).concat(newTag);
                        item['unionTag'] = newUnionTag
                    }
                    delete item['tagList']
                    item['unionTag'] = JSON.stringify(item['unionTag'])


                    item['newUnionTag'] = JSON.stringify(newUnionTag)
                })

                let payload = {
                    clientList:this.multipleSelection
                }

                this.$request("/api/tags/setCustomersTags/1_0", payload, "POST").then((data) => {
                    this.$message.success("批量设置标签成功")
                    this.back()
                })
            },
        }
    }
</script>

<style scoped>

</style>
